﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.ComponentModel.DataAnnotations;
using Budgeter.Extensions;
using Budgeter.Models;

namespace Budgeter.ViewModels.Budget.CreateOrEdit
{

    public class ViewModel
    {

        public class Entry
        {
            [Display(Name = "Category")]
            public string Category { get; set; }
            [Display(Name = "Name")]
            public string Name { get; set; }
            [Display(Prompt = "$")]
            [DataType(DataType.Currency)]
            public decimal? Amount { get; set; }
            [Display(Name = "Intervals")]
            public int? IntervalId { get; set; }
            public bool IsIncome { get; set; }

            public override bool Equals(object obj)
            {
                return string.Compare(Name, ((Entry)obj).Name) == 0;
            }

            public override int GetHashCode()
            {
                // Hash code calc as per people smarter than me: http://stackoverflow.com/a/263416/246901
                int categoryHashCode = Category == null ? 0 : Category.GetHashCode();
                int nameHashCode = Name == null ? 0 : Name.GetHashCode();
                unchecked
                {
                    return (17 * 23 + categoryHashCode) * 23 + nameHashCode;
                }
            }
        }

        [HiddenInput(DisplayValue = false)]
        [Required]
        public int BudgetId { get; set; }

        [Display(Name = "Interval")]
        [Required]
        public int? IntervalId { get; set; }

        public IEnumerable<Entry> Entries { get; set; }

        public IEnumerable<Interval> AllIntervals { get; set; }

        [Display(Name = "Receipt Number")]
        public int ReceiptNumber { get; set; }

        public string IntervalsAsJson { get; set; }
    }

}
